package com.springcloud.consumer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.springcloud.consumer.command.UserCommand;
import com.springcloud.consumer.domain.User;

@Service
public class HelloService {

	@Autowired
	RestTemplate restTemplate;

	@HystrixCommand(fallbackMethod="helloFallback")
	public String helloService() {

		return restTemplate.getForEntity("http://SERVICE-FRONTEND/hi?name={1}", String.class, "emin").getBody();
	}
	
	public String helloFallback(){
		return "error";
	}
	
	public User getUserfromId(int id){
		User user = new UserCommand(com.netflix.hystrix.HystrixCommand.Setter.withGroupKey(
				HystrixCommandGroupKey.Factory.asKey("")),restTemplate, 1).execute();
		return user;
	}
}
